﻿using System.Windows;
#if WPF
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Data;
#else
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
using Windows.Foundation;
using Windows.UI.Xaml.Data;
#endif

namespace Eternal.DataVisualization
{
    public class AreaSeries : AxisType
    {

        protected internal override void OnDrawSegment()
        {
            base.OnDrawSegment();
            if (XAxis != null && YAxis != null)
            {
                SegmentInfos.Clear();
                SegmentPanel.Children.Clear();
                double dataCount = ActualXData.Count;

                var path = new Path();

                SegmentPanel.Children.Add(path);
                ApplyBrush(path, 0);

                var figure = new PathFigure();
                var segmentGeometry = new PathGeometry();
                LineSegment lineSegment;
                var start = YAxis.Start;

                figure.StartPoint = new Point(ValueToCoordianteXAxis(0), ValueToCoordianteYAxis(start));

                for (var i = 0; i < ActualYData.Count; i++)
                {
                    lineSegment = new LineSegment();
                    lineSegment.Point = new Point(ValueToCoordianteXAxis(i), ValueToCoordianteYAxis(ActualYData[i]));
                    figure.Segments.Add(lineSegment);
                }

                lineSegment = new LineSegment();
                lineSegment.Point = new Point(ValueToCoordianteXAxis(dataCount - 1), ValueToCoordianteYAxis(start));
                figure.Segments.Add(lineSegment);
                figure.IsClosed = true;
                segmentGeometry.Figures.Add(figure);
                path.Data = segmentGeometry;
            }
        }
    }
}
